/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package adcomputer;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Edgar
 */
public class DatosCliente extends javax.swing.JPanel {
String nombrebuscar;

Cliente c1;
    /**
     * Creates new form DatosCliente
     */
    public DatosCliente() {
        initComponents();
        modificab.setEnabled(false);
        modificarb.setEnabled(false);
          modificab.setVisible(false);
        modificarb.setVisible(false);
        
    }
public void ModificarDatos()
{   
        try {
            modificab.setEnabled(true);
            //modificab.removeAll();
                modificarb.setEnabled(true);
                guardarb.setEnabled(false);
                guardarb.setVisible(false);
                 modificab.setVisible(true);
                 modificarb.setVisible(true);
        idj.setVisible(false);
                BaseDeDatos bd= new BaseDeDatos();
        bd.conectar();
        ResultSet rs =bd.consultar("Select nombre from Clientes");
        while(rs.next())
        {
          modificab.addItem(rs.getString(1));
        }
                
                
                
           
               
               
          
         
          /*private String nombre, calle,colonia, cuidad, correoelectronico, telefono,cp, celular;
            private int id;
            private int deshabilitar;*/
        } catch (SQLException ex) {
            Logger.getLogger(DatosCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
}
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup5 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        nombrej = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        callej = new javax.swing.JTextField();
        cuidadj = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cpj = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        coloniaj = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        telefonoj = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        celularj = new javax.swing.JTextField();
        guardarb = new javax.swing.JButton();
        deshabilitadoj = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        correoj = new javax.swing.JTextField();
        modificarb = new javax.swing.JButton();
        modificab = new javax.swing.JComboBox();
        idj = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(800, 500));

        jLabel1.setText("Nombre");

        nombrej.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombrejActionPerformed(evt);
            }
        });

        jLabel2.setText("Calle");

        callej.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                callejActionPerformed(evt);
            }
        });

        cuidadj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cuidadjActionPerformed(evt);
            }
        });

        jLabel3.setText("Cuidad");

        jLabel4.setText("C.P");

        jLabel5.setText("Colonia");

        coloniaj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                coloniajActionPerformed(evt);
            }
        });

        jLabel6.setText("Telefono");

        jLabel7.setText("Celular");

        guardarb.setText("Guardar");
        guardarb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarbActionPerformed(evt);
            }
        });

        deshabilitadoj.setText("Deshabilitado");
        deshabilitadoj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deshabilitadojActionPerformed(evt);
            }
        });

        jLabel8.setText("CorreoElectronico");

        modificarb.setText("Modificar");
        modificarb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarbActionPerformed(evt);
            }
        });

        modificab.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificabActionPerformed(evt);
            }
        });

        idj.setText("0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(guardarb)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(telefonoj, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(127, 127, 127)
                                .addComponent(modificarb))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(nombrej, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                    .addComponent(callej)
                                    .addComponent(cuidadj)
                                    .addComponent(coloniaj)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(330, 330, 330)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jLabel4))
                            .addComponent(deshabilitadoj)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(48, 48, 48)
                                .addComponent(jLabel8)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cpj, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(celularj, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(correoj, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(modificab, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(185, 185, 185))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nombrej, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deshabilitadoj)
                    .addComponent(modificab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(callej, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(correoj, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4))
                    .addComponent(cuidadj, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                    .addComponent(cpj))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(coloniaj, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(idj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLabel7))
                    .addComponent(telefonoj, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(celularj, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(guardarb)
                    .addComponent(modificarb))
                .addGap(0, 234, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void nombrejActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombrejActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nombrejActionPerformed

    private void callejActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_callejActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_callejActionPerformed

    private void cuidadjActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cuidadjActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cuidadjActionPerformed

    private void coloniajActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_coloniajActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_coloniajActionPerformed

    private void guardarbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarbActionPerformed
        BaseDeDatos bd= new BaseDeDatos();
        String nombre, calle,colonia, cuidad, correoelectronico, telefono,cp, celular;
    int id;
    int deshabilitar;
    
    nombre=nombrej.getText();
    calle=callej.getText();
    colonia=coloniaj.getText();
    cuidad=cuidadj.getText();
    correoelectronico=correoj.getText();
    telefono=telefonoj.getText();
    cp=cpj.getText();
    celular=celularj.getText();
    
    if(deshabilitadoj.isSelected())
    {
      deshabilitar=0;
    }
    else deshabilitar=1;
    
    Cliente cliente= new Cliente(nombre,  calle,  colonia, cuidad,  correoelectronico, telefono,
             cp,  celular,  deshabilitar);        
        
        cliente.guardar();
    }//GEN-LAST:event_guardarbActionPerformed

    private void deshabilitadojActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deshabilitadojActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_deshabilitadojActionPerformed

    private void modificabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificabActionPerformed
nombrebuscar=(String)modificab.getSelectedItem();       
   c1= new Cliente();
            c1.leer(nombrebuscar);
         nombrej.setText(c1.getNombre());
         callej.setText(c1.getCalle());
         coloniaj.setText(c1.getColonia());
         cuidadj.setText(c1.getCuidad());
         cuidadj.setText(c1.getCuidad());
         correoj.setText(c1.getCorreoelectronico());
         telefonoj.setText(c1.getTelefono());
         cpj.setText(c1.getCp());
         celularj.setText(c1.getCelular());
         idj.setText(String.valueOf(c1.getId()));
   
         if(c1.getDeshabilitar()==0)
         {
           deshabilitadoj.setSelected(true);
         }
         else
             deshabilitadoj.setSelected(false);
         
                     
    }//GEN-LAST:event_modificabActionPerformed

    private void modificarbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarbActionPerformed
 BaseDeDatos bd= new BaseDeDatos();
        String nombre, calle,colonia, cuidad, correoelectronico, telefono,cp, celular;
    int id;
    int deshabilitar;
    
    nombre=nombrej.getText();
    calle=callej.getText();
    colonia=coloniaj.getText();
    cuidad=cuidadj.getText();
    correoelectronico=correoj.getText();
    telefono=telefonoj.getText();
    cp=cpj.getText();
    celular=celularj.getText();
    
    if(deshabilitadoj.isSelected())
    {
      deshabilitar=0;
    }
    else deshabilitar=1;
    
    Cliente cliente= new Cliente(nombre,  calle,  colonia, cuidad,  correoelectronico, telefono,
             cp,  celular,  deshabilitar);        
        cliente.setId(Integer.parseInt(idj.getText()));
        cliente.modificar();        // TODO add your handling code here:
    }//GEN-LAST:event_modificarbActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup5;
    private javax.swing.JTextField callej;
    private javax.swing.JTextField celularj;
    private javax.swing.JTextField coloniaj;
    private javax.swing.JTextField correoj;
    private javax.swing.JTextField cpj;
    private javax.swing.JTextField cuidadj;
    private javax.swing.JCheckBox deshabilitadoj;
    private javax.swing.JButton guardarb;
    private javax.swing.JTextField idj;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JComboBox modificab;
    private javax.swing.JButton modificarb;
    private javax.swing.JTextField nombrej;
    private javax.swing.JTextField telefonoj;
    // End of variables declaration//GEN-END:variables
}
